package com.cjm.connect;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
import java.util.Scanner;

public class test7 {
    public static void main(String[] args) throws IOException, SQLException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name = sc.nextLine();
        System.out.println("请输入密码：");
        String pwd = sc.nextLine();
        //获取文件内容
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/connect"));
//       获取连接数据库内容
        String user=properties.getProperty("username");
        String password1=properties.getProperty("password");
        String driver=properties.getProperty("driver");
        String url=properties.getProperty("url");
//      提交数据，连接成功
        Connection connection = DriverManager.getConnection(url, user, password1);
        System.out.println("数据库连接成功");
//      对数据库操作
        String sql="update admin set name=? where password=?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,name );
        preparedStatement.setString(2,pwd );
        int resultSet = preparedStatement.executeUpdate();
        System.out.println(resultSet>0?"成功":"失败");
//       关闭流
        preparedStatement.close();
        connection.close();
    }
}
